﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UIT_CV_Management
{
    public partial class UserControlHoiNghiKHKT : UserControl
    {
        bool isEveryThingOK = false;
        bool isTenHoiNgheOK = false;
        bool isDiaDiemOK = false;
        bool isNoiDungOK = false;

        //object
        HoiNghiKHKT hoiNghiKHKT;
        List<BaoCaoCanBo> listBaoCaoCanBo = new List<BaoCaoCanBo>();

        // list UserControlBaoCaoCanBo
        List<UserControlBaoCaoCanBo> listUCBaoCaoCanBo = new List<UserControlBaoCaoCanBo>();

        public UserControlHoiNghiKHKT()
        {
            InitializeComponent();
            tableLayoutPanel1.Padding = new Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0);
            this.hideAllErrorImage();

            this.btnThem_Click(btnThem, EventArgs.Empty);
        }

    private void initLanguage()
    {
        lblTenHoiNghi.Text = Language._("HOINGHIKHKT_FORM_TENHOINGHI_LBL");
        lblThoiGIan.Text = Language._("HOINGHIKHKT_FORM_THOIGIAN_LBL");
        lblDiaDiem.Text = Language._("HOINGHIKHKT_FORM_DIADIEM_LBL");
        lblNoiDung.Text = Language._("HOINGHIKHKT_FORM_NOIDUNG_LBL");
        lblDanhSachBaoCaoCanBo.Text = Language._("HOINGHIKHKT_FORM_DANHSACHBAOCAOCANBO_LBL");
    }

        private void hideAllErrorImage()
        {
            pictureBoxTenHoiNghi.Visible = false;
            pictureBoxTenHoiNghi.Visible = false;
            pictureBoxNoiDung.Visible = false;
        }
        private void txbTenHoiNghi_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbTenHoiNghi.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isTenHoiNgheOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbTenHoiNghi.BackColor = Color.Tomato;
                utpTip.Value = Language._("HOINGHIKHKT_FORM_TIP_TENHOINGHI_NULL");
                utpTip.Visible = true;
                pictureBoxTenHoiNghi.Visible = false;
            }
            else
            {
                isTenHoiNgheOK = true;
                txbTenHoiNghi.BackColor = Color.White;
                pictureBoxTenHoiNghi.Visible = true;
                utpTip.Visible = false;
            }
        }

        private void txbDiaDiem_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbDiaDiem.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isDiaDiemOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbDiaDiem.BackColor = Color.Tomato;
                utpTip.Value = Language._("HOINGHIKHKT_FORM_TIP_DIADIEM_NULL");
                utpTip.Visible = true;
                pictureBoxDiaDiem.Visible = false;
            }
            else
            {
                isDiaDiemOK = true;
                txbDiaDiem.BackColor = Color.White;
                pictureBoxDiaDiem.Visible = true;
                utpTip.Visible = false;
            }
        }

        private void txbNoiDung_Validating(object sender, CancelEventArgs e)
        {
            bool isHasError = false;

            if (txbNoiDung.Text.Trim() == "")
                isHasError = true;

            if (isHasError)
            {
                isNoiDungOK = false;
                
                // change NoiSinh's background color to Tomato
                // Add UserTip
                txbNoiDung.BackColor = Color.Tomato;
                utpTip.Value = Language._("HOINGHIKHKT_FORM_TIP_NOIDUNG_NULL");
                utpTip.Visible = true;
                pictureBoxNoiDung.Visible = false;
            }
            else
            {
                isNoiDungOK = true;
                txbNoiDung.BackColor = Color.White;
                pictureBoxNoiDung.Visible = true;
                utpTip.Visible = false;
            }
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            UserControlBaoCaoCanBo UCBaoCaoCanBo = new UserControlBaoCaoCanBo();
            UCBaoCaoCanBo.Anchor = AnchorStyles.Right | AnchorStyles.Left;
            listUCBaoCaoCanBo.Add(UCBaoCaoCanBo);

            //add to panel
            this.tableLayoutPanel1.Controls.Add(UCBaoCaoCanBo);
        }

        private bool isListBaoCaoCanBoOK()
        {
            bool ok = true;
            foreach (UserControlBaoCaoCanBo UCBaoCaoCanBo in listUCBaoCaoCanBo)
            {
                ok = ok && UCBaoCaoCanBo.isBaoCaoCanBoOK();
            }
            return ok;
        }
        public bool isHoiNghiKHKTOK()
        {
            // Validate
            txbTenHoiNghi_Validating(txbTenHoiNghi, null);
            txbDiaDiem_Validating(txbDiaDiem, null);
            txbNoiDung_Validating(txbNoiDung, null);

            isEveryThingOK = this.isListBaoCaoCanBoOK() && isTenHoiNgheOK && isNoiDungOK && isDiaDiemOK;
            return isEveryThingOK;
        }
        public HoiNghiKHKT getHoiNghiKHKT()
        {
            if (this.isHoiNghiKHKTOK())
            {
                for (int i = 0; i < listUCBaoCaoCanBo.Count; i++)
                {
                    UserControlBaoCaoCanBo UCBaoCao = listUCBaoCaoCanBo[i];
                    BaoCaoCanBo baoCao = new BaoCaoCanBo(UCBaoCao.TenBaoCao, i);
                    baoCao.TenBaoCao = UCBaoCao.TenBaoCao;
                    // add to list BaoCao
                    listBaoCaoCanBo.Add(baoCao);
                }

                // init hoiNghi
                hoiNghiKHKT = new HoiNghiKHKT(txbTenHoiNghi.Text, dtpThoiGIan.Value, txbDiaDiem.Text, txbNoiDung.Text, listBaoCaoCanBo);
            }
            return hoiNghiKHKT;
        }
    }
}
